﻿package core.drawing
{
    import core.enum.*;
    import flash.events.*;
    import flash.geom.*;

    final public class HandTool extends Tool
    {
        var panorg:Point;
        var mousedown:Point;

        public function HandTool(param1:Tuyitu)
        {
            super(param1, ToolType.Hand, false);
            return;
        }// end function

        override public function MouseDown(event:MouseEvent) : void
        {
            this.UpdateReferences();
            ed.cursor.freeze = true;
            ed.addEventListener(MouseEvent.MOUSE_MOVE, this.MouseDrag, false, 1, true);
            ed.addEventListener(MouseEvent.MOUSE_UP, this.MouseUp, false, 1, true);
            this.panorg = new Point(document.x, document.y);
            this.mousedown = new Point(ed.stage.mouseX, ed.stage.mouseY);
            return;
        }// end function

        override public function MouseDrag(event:MouseEvent) : void
        {
            document.x = this.panorg.x + (ed.stage.mouseX - this.mousedown.x);
            document.y = this.panorg.y + (ed.stage.mouseY - this.mousedown.y);
            canvas.CheckBounds();
            canvas.UpdateAfterPan();
            return;
        }// end function

        override public function MouseUp(event:MouseEvent) : void
        {
            ed.cursor.freeze = false;
            ed.removeEventListener(MouseEvent.MOUSE_MOVE, this.MouseDrag, false);
            ed.removeEventListener(MouseEvent.MOUSE_UP, this.MouseUp, false);
            if (!AppState.OnCanvas)
            {
                ed.cursor.Set(ToolType.None);
            }
            return;
        }// end function

    }
}
